package com.wwtech.epp.ui.adapter.work;

import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.socks.library.KLog;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.Daily;

import java.util.List;







/**
 * @author hzp
 * @Package com.wwtech.epp.ui.activity.work
 * @Description: $description  adapter of DailyFragment
 * @date 2017/12/07 17:36:20
 */

public class DailyListAdapter extends BaseQuickAdapter<Daily.DataBean.ListBean, BaseViewHolder> {

    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public DailyListAdapter(@Nullable List<Daily.DataBean.ListBean> data) {
       super(R.layout.daily_list_item, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Daily.DataBean.ListBean item) {
        baseViewHolder.setText(R.id.time, "发送时间：" + item.getCreateTime().substring(0, 16))
                .setText(R.id.kind, item.getReportType());
        StringBuilder text = new StringBuilder();
        KLog.i(type);
        if ("我发出的".equals(type)) {
            text.append("接收人：");
            for (int i = 0; i < item.getReceiveUserNames().size(); i++) {
                text.append(item.getReceiveUserNames().get(i) + " ");
            }
        } else {
            text .append("发送人：" + item.getSendUserName());
        }
        SpannableStringBuilder spannableString = new SpannableStringBuilder();
        spannableString.append(text);
        ForegroundColorSpan colorSpan1 = new ForegroundColorSpan(mContext.getResources().getColor(R.color.color_333));
        ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(mContext.getResources().getColor(R.color.main_color));
        spannableString.setSpan(colorSpan1, 0, 4, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        spannableString.setSpan(colorSpan2, 4, text.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        baseViewHolder.setText(R.id.name, spannableString);
    }
}